package org.example.basic.day02;

public class Demo06继承 {

    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.name = "旺财";
        dog.color = "白色";
        dog.age = 5;
        System.out.println(dog);
        Cat cat = new Cat();
        cat.name = "小猫";
        cat.color = "黑色";
        cat.leg = 4;
        System.out.println(cat);
    }
}

/**
 * 动物类共有属性
 */
class Animal{
    String name;
    String color;
}
/**
 * 狗类继承动物类
 */
class Dog extends Animal{
    int age;

    @Override
    public String toString() {
        return "Dog{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", color='" + color + '\'' +
                '}';
    }
}
/**
 * 猫类继承动物类
 */
class Cat extends Animal{
    int leg;

    @Override
    public String toString() {
        return "Cat{" +
                "leg=" + leg +
                ", name='" + name + '\'' +
                ", color='" + color + '\'' +
                '}';
    }
}
